package com.maycur.ctrip.enumeration;

import org.apache.commons.lang3.StringUtils;

/**
 * Created by JoeyXin on 6/30/16.
 */
public enum PayType {
    /*
    机票支付方式:
    CCARD("信用卡支付"),
    CHECK("支票支付"),
    UNPAY("银联在线支付"),
    ACCNT("公司账户支付"),
    PCARD("手机支付"),
    TMPAY("礼品卡支付"),
    CASH("现金支付"),
    APPAY("AirPlus 支付");

    酒店支付方式:现金;公司账户;礼品卡支付;信用卡支付

    火车票支付方式: ACCNT:公司账户支付, CCard:信用卡支付, CASH:现付
    */

    CASH_PAY("现金支付","CASH"),
    CREDIT_CARD_PAY("信用卡支付", "CCARD"),
    CHINA_UNION_PAY("银联在线支付", "UNPAY"),
    ALIPAY_PAY("支付宝", null),
    WECHAT_PAY("微信支付", null),
    APPLE_PAY("Apple pay", null),
    PAYPAL_PAY("PayPal 支付", null),
    AIRPLUS_PAY("AirPlus 支付", "APPAY"),
    CHECK_PAY("支票支付", "CHECK"),
    CORP_ACCOUNT_PAY("公司账户支付", "ACCNT"),
    GIFT_CARD_PAY("礼品卡支付", "TMPAY");

    private final String description1;

    private final String description2;

    PayType(String description1, String description2) {
        this.description1 = description1;
        this.description2 = description2;
    }


    public String getDescription1() {
        return description1;
    }

    public String getDescription2() {
        return description2;
    }

    public static PayType fromDesc(String desc){
        if(StringUtils.isEmpty(desc)) {
            return null;
        }
        for(PayType payType:PayType.values()){
            if(desc.trim().equalsIgnoreCase(payType.description1) || desc.trim().equalsIgnoreCase(payType.description2)){
                return payType;
            }
        }
        return null;
    }

    public static PayType fromName(String name){
        if(StringUtils.isEmpty(name)) {
            return null;
        }
        for(PayType payType:PayType.values()){
            if(payType.name().equalsIgnoreCase(name.trim())){
                return payType;
            }
        }
        return null;
    }
}
